<?php

/**
 * Pes for PHP 5.3+
 *
 * Copyright (c) 2013 phpeskill.com (http://www.pescms.com)
 *
 * For the full copyright and license information, please view
 * the file LICENSE.md that was distributed with this source code.
 */

namespace App\User;

use Core\Db\Db as Db;
use Expand\Verify as Verify;

/**
 * PSE前台首页
 * @author LazyPHP
 * @version 1.0
 */
class Register extends Common {

    /**
     * 初始化注册页面
     */
    public function index() {
        $this->display();
    }

    /**
     * 执行注册
     */
    public function doReg() {
        $this->checkVerify('verify');
        if ($_POST['agree'] != 'on') {
            $this->error('若同意用户协议，则请勾选');
        }
        
        $data['account'] = $this->is_p('account', '请填写登陆账号');
        $data['password'] = md5(md5($this->is_p('password', '请填写登陆账号')));
        $repassword = md5(md5($this->is_p('repassword', '请填写登陆账号')));
        if($data['password'] != $repassword){
            $this->error('两次密码不一致!');
        }
        $data['nickname'] = $this->is_p('nickname', '请填写登陆账号');
        $data['mail'] = $this->is_p('mail', '请填写登陆账号');
        $data['tel'] = (int)$this->is_p('tel', '请填写登陆账号');
        //此处需补充一个后台设置
        //例如，是否需要开启邮件验证啊
        $data['user_group_id'] = '2';
        $data['status'] = '1';
        $data['create_time'] = time();
        
        $this->checkAccount($data['account']);
        $this->checkMail($data['mail']);
        $this->checkNickname($data['nickname']);
        $this->checkTel($data['tel']);
        
        $db = $this->db('user');
        $addUser = $db->add($data);
        $this->determineSqlExecResult($addUser, '创建用户失败!');
        
        $this->success('注册成功!', $this->url('User-Index-index'));
    }
    


}